package com.kb.controller.components;

import com.kb.common.ApiResponse;
import com.kb.dto.components.RemoteApiComponentsDTO;
import com.kb.service.ComponentService;
import com.kb.vo.components.ComponentPriceVO;
import com.kb.vo.components.LoginResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/components")
@Api(value = "元器件 通用类", tags = {"元器件 通用类"})
@Slf4j
@RequiredArgsConstructor
public class ComponentsController {

    private final ComponentService componentService;

    @ApiOperation("远程调用接口查询询价接口")
    @PostMapping("/remote_api/query")
    @ResponseBody
    public ApiResponse<List<ComponentPriceVO>> queryRemoteApi(@RequestBody List<RemoteApiComponentsDTO> dtoList) {
        return ApiResponse.<List<ComponentPriceVO>>success(componentService.queryRemoteApi(dtoList));
    }


    @ApiOperation("远程调用询价登录获取token接口")
    @GetMapping("/remote_api/login")

    public ApiResponse<LoginResponseVO> queryRemoteApi(
            @ApiParam(value = "用户名", required = true) @RequestParam String username,
            @ApiParam(value = "密码", required = true) @RequestParam String password) {
        return ApiResponse.<LoginResponseVO>success(componentService.doLogin(username, password));
    }

}